import React from 'react'
import { Renderer } from 'amis'
import moment from 'moment/moment'

/**
 * 时间格式列
 */
class DateTimeColumn extends React.Component<any> {
	formatValue = (value: any): string => {
		try {
			return moment(value).format('YYYY-MM-DD HH:mm:ss')
		} catch {
			return 'invalid date'
		}
	}
	render = () => {
		const data = this.props.data
		const value = data[this.props.name]
		const formatValue = this.formatValue(value)
		return <p>{formatValue}</p>
	}
}

Renderer({
	type: 'ace-col-datetime',
	weight: 100,
})(DateTimeColumn)
export default DateTimeColumn
